package com.vnetoo.osfilesvr;

import java.net.*;
import java.io.*;

public class Server2 {
	private BufferedReader reader;
	private ServerSocket server;
	private Socket socket;

	/**
	 * @param args
	 */
	public Server2() {
	}

	void startServer() {
		try {
			server = new ServerSocket(8888);
			System.out.println("�������׽��ֽ�b���");
			while (true) {
				System.out.println("�ȴ�ͻ���");
				socket = server.accept();
				System.out.println("�����ͻ����l��");
				reader = new BufferedReader(new InputStreamReader(socket
						.getInputStream(), "UTF-8"));// �˴��ܹؼ��utf-8����˻��������
				getMessage();
			}
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	void getMessage() {
		try {
			while (true) {
				System.out.println("�ͻ���" + reader.readLine());
			}
		} catch (Exception e) {
		} finally {
			System.out.println("�ͻ����ж�l��");
			try {
				if (reader != null)
					reader.close();
				if (socket != null)
					socket.close();
				reader = null;
				socket = null;
			} catch (Exception e) {
			}
		}
	}

	public static void main(String[] args) {
		Server2 server = new Server2();
		server.startServer();
	}

}
